package com.erp.myAdapter

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.R
import com.erp.bean.AnZhuangZhiNanBean
import com.erp.bean.AnzhuangZhinanLunboBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_anzhaung_lunbo.view.*
import android.webkit.WebViewClient
import com.erp.activity.GonggaoTextActivity
import com.erp.contacts.Contacts


class AnzhuangLunboAdapter(var context: Context, var zhinanlist: MutableList<AnzhuangZhinanLunboBean>) : BaseAdapter() {
    var minflater: LayoutInflater = LayoutInflater.from(context)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        var h : Header
        if(convertView==null){
            v=minflater.inflate(R.layout.lv_anzhaung_lunbo,null)
            h= Header(v)
            v.tag=h
        }else{
            v=convertView
            h=v.tag as Header
        }
        var bean = zhinanlist[position]
//        h.banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
//        h.banner.setImageLoader(MyImageLoader())
//        h.banner.setImages(bean.lunbopathlist);
//        h.banner.setBannerAnimation(Transformer.CubeIn);// Transformer.BackgroundToForeground
//        h.banner.isAutoPlay(true);
//        h.banner.setDelayTime(5000);
//        h.banner.setIndicatorGravity(BannerConfig.CENTER);
//        h.banner.start();
        if(bean.lunbopathlist.size > 0){

        h.webimg.setVerticalScrollBarEnabled(false) //垂直滚动条不显示
        h.webimg.setHorizontalScrollBarEnabled(false)//水平不显示
        val webSettings = h.webimg.getSettings()
        webSettings.setDisplayZoomControls(false)//隐藏webview缩放按钮
        webSettings.setJavaScriptEnabled(true)
        webSettings.setUseWideViewPort(true)//屏幕适配:设置webview推荐使用的窗口，设置为true
        webSettings.setLoadWithOverviewMode(true)//设置webview加载的页面的模式，也设置为true
        webSettings.setAllowFileAccess(true)
        webSettings.setSupportZoom(true)//是否支持缩放
        webSettings.setBuiltInZoomControls(true)//添加对js功能的支持
        h.webimg.setWebViewClient(WebViewClient())
        h.webimg.setBackgroundColor(0)
        val gifPath = "file:///android_asset/animation.gif"
        h.webimg.loadUrl(bean.lunbopathlist[0])

        }
//        if(bean.lunbopathlist.size > 0){
//            Myutil.showhttpphoto(bean.lunbopathlist[0], h.xianshi, context)
//        }
        if(bean.beijingpath != ""){
            Myutil.showhttpphoto(bean.beijingpath, h.beijing, context)
        }
        h.beijing.setOnClickListener({
            val intent = Intent(context as Activity, GonggaoTextActivity::class.java)
            intent.putExtra("url", Contacts.ZHINAN + zhinanlist[position].id + "/detail?mobile=1" )
            intent.putExtra("title",zhinanlist[position].title)
            context.startActivity(intent)
        })
        return v
    }

    override fun getItem(position: Int): Any = zhinanlist[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = zhinanlist.size
    class Header(var v : View){
//        val banner = v.banner
        var xianshi = v.xianshi
        var beijing = v.beijing
        var webimg = v.webimg
    }
}